// store命名
import { StoreName } from '@store/store-name';

// 用户模块
export const usePurchaseStore = defineStore(StoreName.PURCHASE, {
    state: (): {
        total: number;
        riskAssessment: RiskAssessment[];
        able: string[];
        disable: string[];
    } => ({
        total: 0,
        riskAssessment: [],
        able: [
            'customerAbbreviation',
            'orderStatus',
            'productName',
            'supplierAbbreviation',
            'tissueSize',
            'corrugatedSize',
            'materialQuality',
            'crimping',
            'purchaseNumber',
            'arrivalTo',
            'purchaseNotes',
            'printFlag',
            'arrivalDate',
            'createdAt',
        ],
        disable: [
            'order',
            'orderNo',
            'productSize',
            'spell',
            'orderNumber',
            'orderRemark',
            'procurementControlInfo',
            'procurementControlReceipts',
            'orderDeliveryDate',
            'creator',
            // 永不开启 allColumn不录入
            'available',
        ],
    }),
    actions: {
        // 添加采购风险评估
        async addPurchaseRiskAssessment(riskAssessment: RiskAssessment[], total: number) {
            // 清空数据
            this.riskAssessment.splice(0);
            // 添加数据
            this.total = total;
            riskAssessment.forEach((risk) => {
                this.riskAssessment.push(risk);
            });
        },
    },
    persist: {
        storage: localStorage,
    },
});
